clear all
capture set more off

/*
* automatically set working directory
foreach i in "Z:/Dropbox/projects/WWI German Discrimination"				///
			 "D:/Dropbox/projects/WWI German Discrimination"				///
			 "C:/Users/anf137/Dropbox/projects/WWI German Discrimination"	///
			 "your directiory" {

			 global path "`i'"
			 confirmdir "$path"
			 if `r(confirmdir)'==0 continue, break
}
*/


	
	
*******************************************************************************************************************************************
* TABLE 1
*******************************************************************************************************************************************
use "$path/Replication/cleaned_data/county_panel_shortrun.dta", clear

	global controls "c.prewarGer i.year draftrate_amm1845post c.prewarPOP#1.post c.prewarMFGL#1.post c.prewarMF#1.post c.prewarurb#1.post"

	
	* Only counties w newspapers

	* Column 1
	areg enemy_share_npcom_main casrate_1845amm $controls if mindist==1 & year==1920, a(state) robust
		qui su enemy_share_npcom if year==1920
		estadd scalar ymean = r(mean)
		estadd scalar R2 = e(r2_a)
		est store regN1
		cap drop N1
		gen N1 = e(sample)

	* Column 2
	areg hun_share_npcom_main casrate_1845amm $controls if mindist==1 & year==1920, a(state) robust
		qui su hun_share_npcom if year==1920
		estadd scalar ymean = r(mean)
		estadd scalar R2 = e(r2_a)
		est store regN2
		cap drop N2
		gen N2 = e(sample)

	* Column 3
	areg tar_share_npcom_main casrate_1845amm $controls if mindist==1 & year==1920, a(state) robust
		qui su tar_share_npcom if year==1920
		estadd scalar ymean = r(mean)
		estadd scalar R2 = e(r2_a)
		est store regN3
		cap drop N3
		gen N3 = e(sample)

		
	* with neighboring counties

	* Column 4
	areg enemy_share_npcom casrate_1845amm $controls if (newspaper_neighbor==1 | mindist==1) & year==1920 [aw=weight], a(state) robust
		qui su enemy_share_npcom if year==1920
		estadd scalar ymean = r(mean)
		estadd scalar R2 = e(r2_a)
		est store regN4

	* Column 5
	areg hun_share_npcom casrate_1845amm $controls if (newspaper_neighbor==1 | mindist==1) & year==1920 [aw=weight], a(state) robust
		qui su hun_share_npcom if year==1920
		estadd scalar ymean = r(mean)
		estadd scalar R2 = e(r2_a)
		est store regN5

	* Column 6
	areg tar_share_npcom casrate_1845amm $controls if (newspaper_neighbor==1 | mindist==1) & year==1920 [aw=weight], a(state) robust
		qui su tar_share_npcom if year==1920
		estadd scalar ymean = r(mean)
		estadd scalar R2 = e(r2_a)
		est store regN6
	
	* store table as tex file
	#delimit ;
	esttab regN* using "$path/Replication/tables/table1.tex",
		   replace star(* 0.10 ** 0.05 *** 0.01)
		   keep(casrate_1845amm)
		   coeflabels(casrate_1845amm "WWI Casualty Rate")
		   not collabels(none) nomtitles nonumbers substitute(\_ _) fragment plain
		   cells("b(fmt(3)star)" "se(fmt(3)par)")
		   stats(ymean N R2, fmt(%9.3fc %9.0fc %9.3fc)
		   label("\\[-1em] \hline Outcome mean"
				 "Observations"
				 "Adj.\ R$^2$"));
	#delimit cr
	est clear

	
	
*******************************************************************************************************************************************
* TABLE 2
*******************************************************************************************************************************************
use "$path/Replication/cleaned_data/linked_Germans_estimation_sample.dta", clear

	global controls "c.draftrate i.urban1910 i.skill1910 i.farm1910 i.empstat1910 i.lit1910 i.marst1910 i.yrsusa21910 c.famsize1910 i.school1910 i.labforce1910 c.wksunemp1910"
	
	reghdfe mover treat $controls i.year if abe_nysiis_standard==1, a(fips1910 birthyr bpl) cluster(fips)
		qui su mover if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		est store regA1
		
	reghdfe dist treat $controls missdist i.year if maxmover==1 & abe_nysiis_standard==1, a(fips1910 birthyr bpl) cluster(fips)
		qui su dist if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		est store regA2
		
	reghdfe notmidwest20 treat $controls i.year if maxmover==1 & abe_nysiis_standard==1, a(fips1910 birthyr bpl) cluster(fips)
		qui su notmidwest20 if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		est store regA3
		
	reghdfe nonat treat $controls i.year if maxmover==1 & abe_nysiis_standard==1, a(fips1910 birthyr bpl) cluster(fips)
		qui su nonat if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		est store regA4
		
	reghdfe lasttname_change treat $controls i.year if maxmover==1 & abe_nysiis_standard==1, a(fips1910 birthyr bpl) cluster(fips)
		qui su lasttname_change if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		est store regA5
		
	reghdfe farmer treat $controls i.year if maxmover==1 & abe_nysiis_standard==1, a(fips1910 birthyr bpl) cluster(fips)
		qui su farmer if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		est store regA6


	* store table as tex file
	#delimit ;
	esttab regA* using "$path/Replication/tables/table2.tex",
		   replace star(* 0.10 ** 0.05 *** 0.01)
		   keep(*treat*)
		   coeflabels(treat "Casualty Quintile = 5")
		   not collabels(none) nomtitles nonumbers substitute(\_ _) fragment plain
		   cells("b(fmt(3)star)" "se(fmt(3)par)")
		   stats(N R2 ymean, fmt(%9.0fc %9.3fc %9.3fc) 				
		   label("\\[-1em] \hline Observations"  													
					 "Adj.\ R$^2$"  														
					 "Outcome mean"));
	#delimit cr
	est clear	

	
	
*******************************************************************************************************************************************
* TABLE 3
*******************************************************************************************************************************************

qui
	reghdfe mover treat 1.treat#1.maxnospeakeng10 $controls i.year if abe_nysiis_standard==1, a(fips1910 birthyr bpl) cluster(fips)
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		est store regC1

	reghdfe mover treat 1.treat#1.maxnospeakeng10 1.treat#1.wilhelmfrst $controls i.year if abe_nysiis_standard==1, a(fips1910 birthyr bpl) cluster(fips)
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		est store regC2

	reghdfe mover treat 1.treat#1.maxnospeakeng10 1.treat#1.wilhelmfrst 1.treat#1.germansurname_match $controls i.year if abe_nysiis_standard==1, a(fips1910 birthyr bpl) cluster(fips)
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		est store regC3

	reghdfe mover treat 1.treat#1.maxnospeakeng10 1.treat#1.wilhelmfrst 1.treat#1.germansurname_match 1.treat#i.yrsusa2 $controls i.year if abe_nysiis_standard==1, a(fips1910 birthyr bpl) cluster(fips)
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		est store regC4

	* store table as tex file
	#delimit ;
	esttab regC* using "$path/Replication/tables/table3.tex",
		   replace star(* 0.10 ** 0.05 *** 0.01)
		   keep(treat 1.treat#1.maxnospeakeng10 1.treat#1.wilhelmfrst 1.treat#1.germansurname_match 1.treat#1.yrsusa2 1.treat#2.yrsusa2 1.treat#3.yrsusa2 1.treat#4.yrsusa2)
		   coeflabels(treat "Casualty Quintile = 5"
					  1.treat#1.maxnospeakeng10 "Does not speak English"
					  1.treat#1.wilhelmfrst "First name is Wilhelm"
					  1.treat#1.germansurname_match "German surname"
					  1.treat#1.yrsusa2 "In U.S. 0-5 years"
					  1.treat#2.yrsusa2 "In U.S. 5-10 years"
					  1.treat#3.yrsusa2 "In U.S. 11-15 years"
					  1.treat#4.yrsusa2 "In U.S. 16-20 years")
		   not collabels(none) nomtitles nonumbers substitute(\_ _) fragment plain
		   cells("b(fmt(3)star)" "se(fmt(3)par)")
		   stats(N R2 , fmt(%9.0fc %9.3fc) 				
		   label("\\[-1em] \hline Observations"  													
					 "Adj.\ R$^2$"));
	#delimit cr
	est clear	
		
	
*******************************************************************************************************************************************
* TABLE 4
*******************************************************************************************************************************************
use "$path/Replication/cleaned_data/county_panel_shortrun.dta", clear


	* globals w controls for OLS and IV
	global controls "c.prewarGer i.year draftrate_amm1845post c.prewarPOP#1.post c.prewarMFGL#1.post c.prewarMF#1.post c.prewarurb#1.post"

	* w time varying pop control
	global controls2 "c.prewarGer i.year draftrate_amm1845post c.prewarPOP#1.post c.prewarMFGL#1.post c.prewarMF#1.post totpop mtot c.prewarurb#1.post"

	
	* compute mean outflow
	qui reghdfe lnwages outflow prewarGer draftrate_amm1845post i.year if year>1890, a(id) cluster(id)
	qui su outflow if e(sample) & year==1920
	scalar meanout = `r(mean)'


	* TOP PANEL
	***************************************************************************************************************************************
	
	* PANEL A COLUMN 1: control for prewar ger and draft rate
	reghdfe lnwages outflow prewarGer draftrate_amm1845post i.year if year>1890, a(id) cluster(id)
	estadd scalar R2 = e(r2_a)
	estadd scalar cl = e(N_clust)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont1 "Yes"
	est store regB1
	
	* PANEL A COLUMN 2: with the above AND pre-war pop controls
	reghdfe lnwages outflow prewarGer draftrate_amm1845post c.prewarPOP#1.post c.prewarMF#1.post i.year if year>1890 , a(id) cluster(id)
	estadd scalar R2 = e(r2_a)
	estadd scalar cl = e(N_clust)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont1 "Yes"
	estadd local cont2 "Yes"
	est store regB2
	
	* PANEL A COLUMN 3: with the above AND pre-war mfg and urbanization
	reghdfe lnwages outflow prewarGer draftrate_amm1845post c.prewarPOP#1.post c.prewarMF#1.post c.prewarMFGL#1.post c.prewarurb#1.post i.year if year>1890 , a(id) cluster(id)
	estadd scalar R2 = e(r2_a)
	estadd scalar cl = e(df_a_nested)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont1 "Yes"
	estadd local cont2 "Yes"
	estadd local cont3 "Yes"
	est store regB3
	
	* PANEL A COLUMN 4: with the above AND time varying population controls
	reghdfe lnwages outflow prewarGer mtot totpop draftrate_amm1845post c.prewarPOP#1.post c.prewarMF#1.post c.prewarMFGL#1.post c.prewarurb#1.post i.year if year>1890 , a(id) cluster(id)
	estadd scalar R2 = e(r2_a)
	estadd scalar cl = e(df_a_nested)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont1 "Yes"
	estadd local cont2 "Yes"
	estadd local cont3 "Yes"
	estadd local cont4 "Yes"
	est store regB4
	

	* generate upper panel for the table
	#delimit ;
	esttab regB* using "$path/Replication/tables/table4_panelA.tex",			
		   replace star(* 0.10 ** 0.05 *** 0.01) 								
		   keep(*outflow*) 														
		   coeflabels(outflow "Post-WWI $\times$ German Outflow$\_{1910-20}$")	
		   not collabels(none) nomtitles nonumbers substitute(\_ _) fragment plain
		   cells("b(fmt(3)star)" "se(fmt(3)par)") 								
		   stats(N cl meaneff R2 cont1 cont2 cont3 cont4, fmt(%9.0fc %9.0fc %9.3fc %9.3fc %9s %9s %9s %9s) 			
		   label("\\[-1.5em] \hline Observations"  												
				 "Counties"  			
				 "Effect at mean outflow"
				 "Adj.\ R$^2$"  												
				 "\\[-1.5em] \hline Pre-war \% Germans and draft rate"  									
				 "Pre-war population and sex ratio"  									
				 "Pre-war manufacturing and urbanization"						
				 "Time-varying population"));
	#delimit cr
	est clear


	* BOTTOM PANEL
	***************************************************************************************************************************************

	* PANEL B COLUMN 1: log firm size
	reghdfe lnfirmsize outflow $controls if year>1890 & S==1, a(id) cluster(id)
	estadd scalar R2 = e(r2_a)
	estadd scalar cl = e(N_clust)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont "Yes"
	est store regL1
	
	* PANEL B COLUMN 2: log mfg estabs
	reghdfe lnmfgestab outflow $controls if year>1890 & S==1, a(id) cluster(id)
	estadd scalar R2 = e(r2_a)
	estadd scalar cl = e(N_clust)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont "Yes"
	est store regL2
	
	* PANEL B COLUMN 3: log mfg labor
	reghdfe lnmfglaborpc outflow $controls if year>1890 & S==1, a(id) cluster(id)
	estadd scalar R2 = e(r2_a)
	estadd scalar cl = e(df_a_nested)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont "Yes"
	est store regL3
	
	* PANEL B COLUMN 4: log output per capita
	reghdfe lnmfgoutperfirm outflow $controls if year>1890 & S==1, a(id) cluster(id)
	estadd scalar R2 = e(r2_a)
	estadd scalar cl = e(df_a_nested)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont "Yes"
	est store regL4
	
	
	* generate lower panel for the table
	#delimit ;
	esttab regL* using "$path/Replication/tables/table4_panelB.tex",
		   replace star(* 0.10 ** 0.05 *** 0.01)
		   keep(*outflow*)
		   coeflabels(outflow "Post-WWI $\times$ German Outflow$\_{1910-20}$")
		   not collabels(none) nomtitles nonumbers substitute(\_ _) fragment plain
		   cells("b(fmt(3)star)" "se(fmt(3)par)")
		   stats(N cl meaneff R2 cont, fmt(%9.0fc %9.0fc %9.3fc %9.3fc %9s)
		   label("\\[-1.5em] \hline Observations"
				 "Counties"
				 "Effect at mean outflow"
				 "Adj.\ R$^2$"
				 "\\[-1.5em] \hline Controls"));
	#delimit cr
	est clear
	
	
	
*******************************************************************************************************************************************
* TABLE 5
*******************************************************************************************************************************************
	
	* compute mean outflow
	qui reghdfe lnwages outflow prewarGer draftrate_amm1845post i.year if year>1890, a(id) cluster(id)
	qui su outflow if e(sample) & year==1920
	scalar meanout = `r(mean)'


	* TOP PANEL
	***************************************************************************************************************************************	

	* PANEL A COLUMN 1: control for prewar ger and draft rate
	ivreghdfe lnwages (outflow= 5.Q5_casrate_1845amm#1.post) prewarGer draftrate_amm1845post c.prewarPOP#1.post i.year if year>1890 & S==1, a(id) cluster(id)
	estadd scalar fF = e(widstat)
	estadd scalar cl = e(N_clust)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont1 "Yes"
	est store regB1
	
	* PANEL A COLUMN 2: with the above AND pre-war pop controls
	ivreghdfe lnwages (outflow= 5.Q5_casrate_1845amm#1.post) prewarGer draftrate_amm1845post c.prewarPOP#1.post c.prewarMF#1.post i.year if year>1890 , a(id) cluster(id)
	estadd scalar fF = e(widstat)
	estadd scalar cl = e(N_clust)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont1 "Yes"
	estadd local cont2 "Yes"
	est store regB2
	
	* PANEL A COLUMN 3: with the above AND pre-war mfg and urbanization
	ivreghdfe lnwages (outflow= 5.Q5_casrate_1845amm#1.post) prewarGer draftrate_amm1845post c.prewarPOP#1.post c.prewarMF#1.post c.prewarMFGL#1.post c.prewarurb#1.post i.year if year>1890 , a(id) cluster(id)
	estadd scalar fF = e(widstat)
	estadd scalar cl = e(df_a_nested)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont1 "Yes"
	estadd local cont2 "Yes"
	estadd local cont3 "Yes"
	est store regB3
	
	* PANEL A COLUMN 4: with the above AND time varying population controls
	ivreghdfe lnwages (outflow= 5.Q5_casrate_1845amm#1.post) prewarGer mtot totpop draftrate_amm1845post c.prewarPOP#1.post c.prewarMF#1.post c.prewarMFGL#1.post c.prewarurb#1.post i.year if year>1890 , a(id) cluster(id)
	estadd scalar fF = e(widstat)
	estadd scalar cl = e(df_a_nested)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd local cont1 "Yes"
	estadd local cont2 "Yes"
	estadd local cont3 "Yes"
	estadd local cont4 "Yes"
	est store regB4
	
	
	* generate upper panel for the table
	#delimit ;
	esttab regB* using "$path/Replication/tables/table5_panelA.tex",			
		   replace star(* 0.10 ** 0.05 *** 0.01) 								
		   keep(*outflow*) 														
		   coeflabels(outflow "Post-WWI $\times$ German Outflow$\_{1910-20}$")	
		   not collabels(none) nomtitles nonumbers substitute(\_ _) fragment plain
		   cells("b(fmt(3)star)" "se(fmt(3)par)") 								
		   stats(N cl meaneff fF cont1 cont2 cont3 cont4, fmt(%9.0fc %9.0fc %9.3fc %9.3fc %9s %9s %9s %9s) 			
		   label("\\[-1.5em] \hline Observations"  												
				 "Counties"  			
				 "Effect at mean outflow"
				 "K-P F-statistic"  												
				 "\\[-1.5em] \hline Pre-war \% Germans and draft rate"  									
				 "Pre-war population and sex ratio"  									
				 "Pre-war manufacturing and urbanization"						
				 "Time-varying population"));
	#delimit cr
	est clear


	* BOTTOM PANEL
	***************************************************************************************************************************************
	

	* PANEL B COLUMN 1: log firm size
	qui ivmediate lnwages $controls if year>1890 & S==1, med(lnfirmsize) treatment(outflow) instrument(IV) a(id) vce(cluster id)
	scalar medeff = e(mepct)
	ivreghdfe lnfirmsize (outflow= 5.Q5_casrate_1845amm#1.post) $controls2 if year>1890 & S==1, a(id) cluster(id)
	estadd scalar fF = e(widstat)
	estadd scalar cl = e(N_clust)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd scalar mediate = medeff
	estadd local cont "Yes"
	est store regJ1	
	
	* PANEL B COLUMN 2: log mfg estabs
	qui ivmediate lnwages $controls if year>1890 & S==1, med(lnmfgestab) treatment(outflow) instrument(IV) a(id) vce(cluster id)
	scalar medeff = e(mepct)
	ivreghdfe lnmfgestab (outflow= 5.Q5_casrate_1845amm#1.post) $controls2 if year>1890 & S==1, a(id) cluster(id)
	estadd scalar fF = e(widstat)
	estadd scalar cl = e(N_clust)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd scalar mediate = medeff
	estadd local cont "Yes"
	est store regJ2
	
	* PANEL B COLUMN 3: log mfg labor
	qui ivmediate lnwages $controls if year>1890 & S==1, med(lnmfglaborpc) treatment(outflow) instrument(IV) a(id) vce(cluster id)
	scalar medeff = e(mepct)
	ivreghdfe lnmfglaborpc (outflow= 5.Q5_casrate_1845amm#1.post) $controls2 if year>1890 & S==1, a(id) cluster(id)
	estadd scalar fF = e(widstat)
	estadd scalar cl = e(df_a_nested)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd scalar mediate = medeff
	estadd local cont "Yes"
	est store regJ3
	
	* PANEL B COLUMN 4: log output per capita
	qui ivmediate lnwages $controls if year>1890 & S==1, med(lnmfgoutpc) treatment(outflow) instrument(IV) a(id) vce(cluster id)
	scalar medeff = e(mepct)
	ivreghdfe lnmfgoutpc (outflow= 5.quincas#1.post) $controls2 if year>1890 & S==1, a(id) cluster(id)
	estadd scalar fF = e(widstat)
	estadd scalar cl = e(df_a_nested)
	estadd scalar meaneff = _b[outflow]*meanout
	estadd scalar mediate = medeff
	estadd local cont "Yes"
	est store regJ4
	
	
	* generate lower panel for the table
	#delimit ;
	esttab regJ* using "$path/Replication/tables/table5_panelB.tex",
		   replace star(* 0.10 ** 0.05 *** 0.01)
		   keep(*outflow*)
		   coeflabels(outflow "Post-WWI $\times$ German Outflow$\_{1910-20}$")
		   not collabels(none) nomtitles nonumbers substitute(\_ _) fragment plain
		   cells("b(fmt(3)star)" "se(fmt(3)par)")
		   stats(N cl meaneff mediate fF cont, fmt(%9.0fc %9.0fc %9.3fc %9.3fc %9.3fc %9s)
		   label("\\[-1.5em] \hline Observations"
				 "Counties"
				 "Effect at mean outflow"
				 "Causal mediation effect (\%)"
				 "K-P F-statistic"
				 "\\[-1.5em] \hline Controls"));
	#delimit cr
	est clear
	
	
	
*******************************************************************************************************************************************
* TABLE 6
*******************************************************************************************************************************************
use "$path/Replication/cleaned_data/linked_Americans_estimation_sample.dta", clear

	global controls "c.draftrate i.urban1910 i.skill1910 i.farm1910 i.empstat1910 i.lit1910 i.marst1910 c.famsize1910 i.school1910 i.labforce1910 c.wksunemp1910"

	scalar meanout = .35


	* TOP PANEL
	***************************************************************************************************************************************	

	* PANEL A COLUMN 1: log occ score
	reghdfe lnoccscore outflow $controls if abe_nysiis_standard==1 & maxmover==0, a(fips birthyr bpl year) cluster(fips)
		qui su lnoccscore if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA1

	* PANEL A COLUMN 2: 
	reghdfe lnlido outflow $controls if abe_nysiis_standard==1 & maxmover==0, a(fips birthyr bpl year) cluster(fips)
		qui su lnlido if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA2

	* PANEL A COLUMN 3: manufacturing worker
	reghdfe mfg outflow $controls if abe_nysiis_standard==1 & maxmover==0, a(fips birthyr bpl year) cluster(fips)
		qui su mfg if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA3

	* PANEL A COLUMN 4: managerial job
	reghdfe mgr outflow $controls if abe_nysiis_standard==1 & maxmover==0 , a(fips birthyr bpl year) cluster(fips)
		qui su mgr if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA4
		
	* PANEL A COLUMN 5: craftsmen job
	reghdfe craft outflow $controls if abe_nysiis_standard==1 & maxmover==0 , a(fips birthyr bpl year) cluster(fips)
		qui su craft if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA5
		
	* PANEL A COLUMN 6: operatives job
	reghdfe op outflow $controls if abe_nysiis_standard==1 & maxmover==0 , a(fips birthyr bpl year) cluster(fips)
		qui su op if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar R2 = e(r2_a)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA6


	* generate top panel for the table
	#delimit ;
	esttab regA* using "$path/Replication/tables/table6_panelA.tex",
		   replace star(* 0.10 ** 0.05 *** 0.01)
		   keep(outflow)
		   coeflabels(outflow "Post-WWI $\times$ German Outflow$\_{1910-20}$")
		   not collabels(none) nomtitles nonumbers substitute(\_ _) fragment plain
		   cells("b(fmt(3)star)" "se(fmt(3)par)")
		   stats(N ymean meaneff R2, fmt(%9.0fc %9.3fc %9.3fc %9.3fc) 				
		   label("\\[-1em] \hline Observations"  													
					 "Outcome mean"  														
					 "Effect at mean outflow"
					 "Adj.\ R$^2$"));
	#delimit cr
	est clear	


	* BOTTOM PANEL
	***************************************************************************************************************************************

	* PANEL B COLUMN 1: log firm size
	ivreghdfe lnoccscore (outflow = treat) $controls if abe_nysiis_standard==1 & maxmover==0, a(fips birthyr bpl year) cluster(fips)
		qui su lnoccscore if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar fF = e(widstat)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA1

	* PANEL B COLUMN 2: 
	ivreghdfe lnlido (outflow = treat) $controls if abe_nysiis_standard==1 & maxmover==0, a(fips birthyr bpl year) cluster(fips)
		qui su lnlido if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar fF = e(widstat)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA2

	* PANEL B COLUMN 3: 
	ivreghdfe mfg (outflow = treat) $controls if abe_nysiis_standard==1 & maxmover==0, a(fips birthyr bpl year) cluster(fips)
		qui su mfg if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar fF = e(widstat)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA3

	* PANEL B COLUMN 4: 
	ivreghdfe mgr (outflow = treat) $controls if abe_nysiis_standard==1 & maxmover==0 , a(fips birthyr bpl year) cluster(fips)
		qui su mgr if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar fF = e(widstat)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA4
		
	* PANEL B COLUMN 5: 
	ivreghdfe craft (outflow = treat) $controls if abe_nysiis_standard==1 & maxmover==0 , a(fips birthyr bpl year) cluster(fips)
		qui su craft if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar fF = e(widstat)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA5
		
	* PANEL B COLUMN 6: 
	ivreghdfe op (outflow = treat) $controls if abe_nysiis_standard==1 & maxmover==0 , a(fips birthyr bpl year) cluster(fips)
		qui su op if e(sample)==1
		estadd scalar ymean = `r(mean)'
		estadd scalar fF = e(widstat)
		estadd scalar cl = e(N_clust)
		estadd scalar meaneff = _b[outflow]*meanout
		est store regA6

	* generate bottom panel for the table
	#delimit ;
	esttab regA* using "$path/Replication/tables/table6_panelB.tex",
		   replace star(* 0.10 ** 0.05 *** 0.01)
		   keep(outflow)
		   coeflabels(outflow "Post-WWI $\times$ German Outflow$\_{1910-20}$")
		   not collabels(none) nomtitles nonumbers substitute(\_ _) fragment plain
		   cells("b(fmt(3)star)" "se(fmt(3)par)")
		   stats(N ymean meaneff fF, fmt(%9.0fc %9.3fc %9.3fc %9.3fc) 				
		   label("\\[-1em] \hline Observations"  											
					 "Outcome mean"
					 "Effect at mean outflow"
					 "K-P F-statistic"));
	#delimit cr
	est clear
	